package com.crm.CLdriving.controller;

import java.util.List;

import javax.validation.Valid;

import com.crm.CLdriving.common.PageResponse;
import com.crm.CLdriving.dto.PageReq.PageNumber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.crm.CLdriving.common.BaseResponse;
import com.crm.CLdriving.dto.req.CostDeleteReqDto;
import com.crm.CLdriving.dto.req.CostInsertReqDto;
import com.crm.CLdriving.dto.req.CostSelectOneReqDto;
import com.crm.CLdriving.dto.req.CostSelectXQReqDto;
import com.crm.CLdriving.dto.req.CostUpdateReqDto;
import com.crm.CLdriving.enu.ResponseEnum;
import com.crm.CLdriving.po.CostPO;
import com.crm.CLdriving.service.CostService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;

@Controller
@RequestMapping("cost")
@Log4j2
@Api(tags="缴费信息管理")
public class CostController {
	
	@Autowired
	private CostService costService;
	
	@PostMapping("insert")
	@ApiOperation("录入缴费信息接口")
	@ResponseBody
	public BaseResponse<?> insert(@Valid @RequestBody CostInsertReqDto costInsertReqDto) {
		log.info("录入缴费信息请求参数"+JSON.toJSONString(costInsertReqDto));
		return costService.insert(costInsertReqDto);	
	}
	
	@PostMapping("select")
	@ApiOperation("查询缴费信息接口")
	@ResponseBody
	public PageResponse<List<CostPO>> select(@RequestBody PageNumber pageNumber) {
		return costService.selectall(pageNumber);
	}
	
	
	@PostMapping("selectXQ")
	@ApiOperation("查询一条缴费信息接口")
	@ResponseBody
	public BaseResponse<List<CostPO>> SelectXQ(@Valid @RequestBody CostSelectXQReqDto costSelectXQReqDto) {
		log.info("筛选框查询缴费信息："+JSON.toJSONString(costSelectXQReqDto));
		if ((costSelectXQReqDto.getIdentityCard()==null || costSelectXQReqDto.getIdentityCard()=="") &&
				(costSelectXQReqDto.getName()==null || costSelectXQReqDto.getName()=="")) {
			return BaseResponse.message(ResponseEnum.MYSXTJ);
		}
		return costService.selectxq(costSelectXQReqDto);	
	}
	
	
	@PostMapping("selectone")
	@ResponseBody
	@ApiOperation("查询一条缴费信息")
	public BaseResponse<CostPO> SelectOne(@Valid @RequestBody CostSelectOneReqDto costSelectOneReqDto){
		return costService.selectone(costSelectOneReqDto);
		
	}
	
	@PostMapping("updateById")
	@ApiOperation("更新缴费信息接口")
	@ResponseBody
	public BaseResponse<?> Update(@Valid @RequestBody CostUpdateReqDto costUpdateReqDto){
		log.info("更新缴费信息请求参数为："+JSON.toJSONString(costUpdateReqDto));
		return costService.update(costUpdateReqDto);
	}
	
	@PostMapping("deleteById")
	@ResponseBody
	@ApiOperation("删除缴费信息接口")
	public BaseResponse<?> DeleteById(@Valid @RequestBody CostDeleteReqDto costDeleteReqDto){
		return costService.deleteById(costDeleteReqDto);
		
	}
 
}
